﻿Imports System.Collections.ObjectModel
Imports System.Collections.Specialized

Public Class RangeObservableCollection(Of T)
    Inherits ObservableCollection(Of T)
    Private _suppressNotification As Boolean = False

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(list As IEnumerable(Of T))
        MyBase.New()
        AddRange(list)
    End Sub

    Protected Overrides Sub OnCollectionChanged(e As NotifyCollectionChangedEventArgs)
        If Not _suppressNotification Then
            MyBase.OnCollectionChanged(e)
        End If
    End Sub

    Public Sub AddRange(list As IEnumerable(Of T))
        If list Is Nothing Then
            Throw New ArgumentNullException("list")
        End If

        _suppressNotification = True

        For Each item As T In list
            Add(item)
        Next
        _suppressNotification = False
        OnCollectionChanged(New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset))
    End Sub
End Class